precision highp float;

uniform sampler2D u_tex;
uniform vec2 u_screen_size;
uniform vec2 u_step;
uniform int u_samples;

varying vec2 v_pos;


vec4 BoxBlur (sampler2D tex, vec2 size, vec2 step, int samples, vec2 pos) {
    vec2 rSize = 1.0 / size;
    float aWeight = 1.0;
    vec4 aColor = texture2D(tex, pos * rSize);
	vec2 aStep = step;
    for (int i = 0; i < samples; ++i) {
        aColor += texture2D(tex, (pos + aStep) * rSize);
        aColor += texture2D(tex, (pos - aStep) * rSize);
        aWeight += 2.0;
        aStep += step;
    }
    return aColor / aWeight;
}

void main () {
	gl_FragColor = BoxBlur(u_tex, u_screen_size, u_step, u_samples, v_pos);
}